//
//  LiveListShareView.m
//  YouinRTCDemo
//
//  Created by 潘欣 on 2025/8/12.
//

#import "LiveListShareView.h"


@interface LiveListShareView ()
/**直播设置**/
@property (nonatomic,strong)UILabel *liveTitle;

@end

@implementation LiveListShareView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.liveTitle = [[UILabel alloc] init];
        self.liveTitle.text = @"直播设置";
        self.liveTitle.textColor = [UIColor blackColor];
        self.liveTitle.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.liveTitle];
        [self.liveTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(self).offset(15);
        }];
        NSArray *titlesArr = [NSArray arrayWithObjects:@"编辑",@"签到",@"分享",@"直播数据",@"删除", nil];
        NSArray *imagesArr = [NSArray arrayWithObjects:@"liveList_edit",@"liveList_signIn",@"liveList_share",@"liveList_data",@"liveList_del", nil];
        
        for (int i = 0; i < titlesArr.count; i ++) {
            UIButton *buttons = [UIButton buttonWithType:UIButtonTypeCustom];
            [buttons setBackgroundImage:[UIImage imageNamed:imagesArr[i]] forState:UIControlStateNormal];
            [buttons addTarget:self action:@selector(buttonsAction:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:buttons];
            buttons.tag = 100+i;
            CGFloat buttonWidth = 54; // 按钮的宽度
                CGFloat spacing = (SCREEN_WIDTH - buttonWidth * 5) / 6; // 计算每个按钮之间的间隔

                // 计算每个按钮的左边距
                CGFloat leftOffset = spacing + (buttonWidth + spacing) * i;

                [buttons mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(self).offset(leftOffset);
                    make.top.mas_equalTo(self.liveTitle.mas_bottom).offset(21);
                    make.size.mas_equalTo(CGSizeMake(buttonWidth, buttonWidth));
                }];
            
            UILabel *titles = [[UILabel alloc] init];
            titles.text = titlesArr[i];
            titles.textColor = RYColorForHex(@"#383838");
            titles.font = [UIFont systemFontOfSize:14];
            [self addSubview:titles];
            [titles mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(buttons.mas_bottom).offset(10);
                make.centerX.mas_equalTo(buttons);
            }];
            
        }
        
        
//
        
        UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
        cancleBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [cancleBtn setTitleColor: RYColorForHex(@"#383838") forState:UIControlStateNormal];
        [cancleBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:cancleBtn];
        
        [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self).offset(-15);
            make.left.right.mas_equalTo(self);
            make.height.offset(30);
        }];
        
        
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.backgroundColor = RYColorForHex(@"#E5E5E5");
        [self addSubview:lineLabel];
        [lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(self);
            make.bottom.mas_equalTo(cancleBtn.mas_top).offset(-10);
            make.height.offset(2);
        }];
        
    }
    return self;
}

- (void)buttonsAction:(UIButton *)sender{
    [self hideView];
    
    if ([self.delegate respondsToSelector:@selector(buttonsBottomAction:)]) {
        [self.delegate buttonsBottomAction:sender];
    }
    
}

- (void)cancelAction
{
    [self hideView];
}
@end
